package com.community.backend.controller;

import com.community.backend.context.BaseContext;
import com.community.backend.pojo.Fee;
import com.community.backend.pojo.dto.FeeQueryDTO;
import com.community.backend.service.FeeService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/*
物业费
 */
@Slf4j
@RestController
@RequestMapping("/Fee")
public class FeeController {
    private final FeeService feeService;

    public FeeController(FeeService feeService) {
        this.feeService = feeService;
    }
    @GetMapping("/page/parking")
    public Result<PageResult> pageParking(FeeQueryDTO feeQueryDTO) {
        PageResult pageResult = feeService.pageQueryParking(feeQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("/page/water")
    public Result<PageResult> pageWater(FeeQueryDTO feeQueryDTO) {
        PageResult pageResult = feeService.pageQueryWater(feeQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("/page/power")
    public Result<PageResult> pagePower(FeeQueryDTO feeQueryDTO) {
        PageResult pageResult = feeService.pageQueryPower(feeQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("/page/gas")
    public Result<PageResult> pageGas(FeeQueryDTO feeQueryDTO) {

        PageResult pageResult = feeService.pageQueryGas(feeQueryDTO);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result save(@RequestBody Fee fee) {
        feeService.save(fee);
        return Result.success("添加成功");
    }
    @PutMapping
    public Result Update(@RequestBody Fee fee) {
        feeService.update(fee);
        return Result.success();
    }

    /**
     * 催款
     * @param id
     * @return
     */
    @GetMapping("/publish/{id}")
    public Result publishFee(@PathVariable String id) {
        System.out.println("使用者id"+BaseContext.getCurrentId());
        feeService.selectById(id);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable String id) {
        feeService.deleteById(id);
        return Result.success("删除成功");
    }

}
